import { defineConfig, loadEnv } from 'vite';
import uni from '@dcloudio/vite-plugin-uni';
import {openDevTools} from './devtools.js';
import { viteMockServe } from 'vite-plugin-mock';

const { resolve } = require('path');

// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
    const env = loadEnv(mode, process.cwd(), '');

    // 自动打开微信小程序开发者工具
    openDevTools(env.UNI_NODE_ENV, env.UNI_PLATFORM);

    return {
        resolve: {
            extensions: [
                '.js', '.vue', '.json'
            ],
            alias: {
                '@': resolve('src'),
                'components': resolve('src/components'),
                'static': resolve('src/static'),
                'tools': resolve('src/tools'),
                'pages': resolve('src/pages')
            }
        },
        plugins: [
            uni(),
            viteMockServe({
                // 这里是vite-plugin-mock的配置项
                mockPath: 'src/mock', // mock文件存放的路径，默认是根目录下的mock文件夹
                supportTs: false, // 如果使用 TypeScript ，设置为true
                // 其他配置项...
            }),
        ],
        server: {
            port: 6067,
            open: true,
            strictPort: false,
            https: false,
            proxy: {
                // '/zsaImg': {
                //     target: 'https://yq.zsacloud.zhonshian.com/zsaImg', // 图片上传
                //     changeOrigin: true,
                //     ws: true,
                //     rewrite: (path) => path.replace(/^\/zsaImg/, '')
                // }
            }
        }
    };
});
